var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(g, f, e) {
    if (im.getServerName().equals("BMS单机") && im.getServerName().equals("BMS至尊体验服") && !im.getServerName().equals("BMS至尊")) {
        im.playerMessage(1, " 使用环境异常，请还原服务端配置。");
        im.dispose();
        return
    }
    if (status == 0 && g == 0) {
        im.dispose();
        return
    }(g == 1) ? status++ : status--;
    selectionLog[status] = e;
    var d = -1;
    if (status <= d++) {
        im.dispose()
    } else {
        if (status === d++) {
            var c = im.itemQuantity(im.getItemId());
            im.askNumber("\r\n背包中有#b#i2630513:# #t2630513:# （无法交换）#k一共有#b" + c + "个#k。你想#b#e一次使用几个#n#k呢？\r\n ", 9010000, c, 1, c, 4)
        } else {
            if (status === d++) {
                im.askYesNo("你想使用#b#i2630513:# #t2630513:# （无法交换）#k道具 #b" + selectionLog[1] + "个#k，获得#b新复古币 " + selectionLog[1] + "个#k吗？", 4, 9010000)
            } else {
                if (status === d++) {
                    var a = im.addNumberForQuestInfo(100246, "point", selectionLog[1]);
                    var b = a - selectionLog[1];
                    im.sendNormalTalk("\r\n拥有的#b新复古币#k从#b" + b + "个#k变成了#b" + a + "个#k！\r\n\r\n\r\n#fUI/UIWindow2.img/QuestIcon/4/0#\r\n#i2630513# #b新复古币 " + selectionLog[1] + "个#k", 4, 9010000, false, true);
                    im.gainItem(im.getItemId(), -selectionLog[1])
                } else {
                    if (status === d++) {
                        im.dispose()
                    }
                }
            }
        }
    }
};